<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #div1{
            background: #00f;
        }
        #div1.red{
            background: red;
        }
    </style>
</head>
<body>
    <div id="div1" class="a b c">DIV1</div>
    <button type="button" id="button1">切换</button>
    <script>
        document.querySelector("#button1").addEventListener("click",function(){
            var div1=document.querySelectorAll("#div1")[0];
            console.log(div1.classList);
            //切换样式
            div1.classList.toggle("red");
            //添加样式
            div1.classList.add("d","e");
            //移除样式
            div1.classList.remove("e");
            //是否包含某个样式
            console.log(div1.classList.contains("red"));
            for(var i=0;i<div1.classList.length;i++){
                console.log(div1.classList[i]);
            }
        },true);
    </script>
</body>
</html>